import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '科室',		name: 'team_id',		type:'select',		loading:true,	idStr:'uuid',	onValue:data=>$fn.onKeShi.call(this,data,{id:'job_id'})},
			{ label: '岗位',		name: 'job_id',				type:'select', 		loading:true},
			{ label: '条码号',		name: 'keyword' },
			{ label: '标本架',		name: 'sf_number' },
		],
	}
	query = { handover_type:0 }
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 科室
			$fn.setRow( forms, 'team_id', await f.getCache({ api:'ke_shi' }) )
			// 岗位
			this.resetData = await f.getCache({ api:'gang_wei' })
			$fn.setRow( forms, 'job_id', this.resetData )
			
			// 
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'receive/index')
	
	// 表单
	cols = [
		{ title: '标本条码', 		dataIndex: 'spec_code', 			...$fn.table.spec_code },
		{ title: '标本架代码', 		dataIndex: 'sf_code', 				...$fn.table.spec_code },
		{ title: '标本架编号', 		dataIndex: 'sf_number', 			...$fn.table.spec_code },
		{ title: '实验号', 			dataIndex: 'lb_tpl', 				...$fn.table.spec_code },
		{ title: '岗位', 			dataIndex: 'job_id', 				width:150 },
		{ title: '科室', 			dataIndex: 'team_name', 			width:150 },
		{ title: '项目名称', 		dataIndex: 'kind_str', 				width:200 },
		{ title: '创建人', 			dataIndex: 'founder', 				...$fn.table.name	 },
		{ title: '创建日期', 		dataIndex: 'created_at',  			...$fn.table.time},
	]
	
	render(){
		return (
			<Page title='标本待领取'>
				{/* 搜索 */}
				{ SearchForm.call(this, {resetField: 'job_id'}) }
				{/* 表格 */}
				{ Table.call(this, {isInit: window.isInit}) }
			</Page>
		)
	}
}

export default Index